//
//  JFViewControllerHelper.m
//  JFKit
//
//  Created by victor lau on 2018/12/13.
//  Copyright © 2018年 Alan Wang. All rights reserved.
//

#import "JFViewControllerHelper.h"


@implementation JFViewControllerHelper

#pragma mark    获取当前正在显示的界面

/**
 获取当前正在显示的界面
 
 @param rootViewController UIViewController description
 @return return value description
 */
+ (UIViewController *)topViewController:(UIViewController *)rootViewController
{
    UIViewController *topViewController = rootViewController;
    if (topViewController.presentedViewController) {
        return [self topViewController:topViewController.presentedViewController];
    }
    if ([topViewController isKindOfClass:[UINavigationController class]]) {
        return [self topViewController:((UINavigationController *)topViewController).viewControllers.lastObject];
    }
    if ([topViewController isKindOfClass:[UITabBarController class]]) {
        return [self topViewController:((UITabBarController *)topViewController).selectedViewController];
    }
    return topViewController;
}

/**
 当前的viewController
 
 @return return value description
 */
+(UIViewController *)topViewController
{
    UIViewController * currentController;
    UIWindow * window= [UIApplication sharedApplication].keyWindow;
    UIViewController * windowRootVC = window.rootViewController;
    
    currentController = [self topViewController:windowRootVC];
    return currentController;
}




@end
